package good

import (
	"api/pb/good"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetGoodInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetGoodInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGoodInfoLogic {
	return &GetGoodInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetGoodInfoLogic) GetGoodInfo(req *types.GoodIDRequest) (resp *types.Good, err error) {
	info, err := l.svcCtx.GoodRpc.GetGoodByID(l.ctx, &good.IDRequest{Id: req.Id})
	if err != nil {
		return nil, err
	}
	return &types.Good{Id: info.Id, Name: info.Name, Price: info.Price, Stock: info.Stock}, nil
}
